// src/components/countdown/index.js
import $CountDown from '../../utils/countdown.js'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    startTime: {
      type: Number,
      value: 0
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    data: {},
    hours: 0
  },
  attached: function() {
    const data = this.timeFormat(this.properties.startTime)
    this.setData({
      data: data
    })
  },

  /**
   * 组件的方法列表
   */
  methods: {
    add0(m) {
      return m < 10 ? '0' + m : m
    },
    timeFormat(timestamp) {
      var time = new Date(timestamp)
      //var time = getDate(timestamp)
      var year = time.getFullYear()
      var month = time.getMonth() + 1
      var date = time.getDate()
      var hours = time.getHours()
      var minutes = time.getMinutes()
      var seconds = time.getSeconds()
      return {
        month: this.add0(month),
        date: this.add0(date),
        hours: this.add0(hours),
        minutes: this.add0(minutes),
        seconds: this.add0(seconds)
      }
    }
  }
})
